import Cookies from 'js-cookie'
const app = {
  state: {
    parentRoute: null, // 上级目录
    sidebar: {
      opened: !+Cookies.get('sidebarStatus')
    },
    listPagePars: new Map(),
    menuList: [],
    countryCityObjectList: [],
  },
  mutations: {
    setCountryCityData: (state, data) => {
      state.countryCityObjectList = data
    },
    SET_MENULIST: (state,data) => {
      state.menuList = data
    },
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('sidebarStatus', 1)
      } else {
        Cookies.set('sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
    },
    SETPARENTROUTER: (state, route) => {
      state.parentRoute = route
    },
    SAVE_LIST_PAGE_PARS: (state, {path, pars}) => {
      state.listPagePars.set(path, pars)
    }
  },
  actions: {
    saveListPagePars: ({commit}, {path,pars}) => {
      commit('SAVE_LIST_PAGE_PARS', {path, pars})
    },
    setParentRoute: ({ commit }, route) => {
      commit('SETPARENTROUTER', route)
    },
    ToggleSideBar: ({ commit }) => {
      commit('TOGGLE_SIDEBAR')
    },
    changeMenuList: (context, data) => {
      context.commit('SET_MENULIST', data)
    }
  }
}

export default app
